package com.da.javatest.niuke.baodian;

/**
 * @author chenlida
 * @date 2020/10/4 11:46
 * https://www.nowcoder.com/practice/2442435405fa432b99b8ec1cb0315902?tpId=8&tqId=10994&rp=1&
 * ru=%2Fta%2Fcracking-the-coding-interview&qru=%2Fta%2Fcracking-the-coding-interview%2Fquestion-ranking
 */
public class C2Reverse {
    public static void main(String[] args) {
        System.out.println(reverseString("abcdefgh"));
        System.out.println(reverseString("aaaacbbbb"));
    }

    public static String reverseString(String iniString) {
        if (iniString == null || iniString.length() < 2) {
            return iniString;
        }
        int size = iniString.length();
        char[] chars = iniString.toCharArray();
        for (int i = 0; i < size / 2; i++) {
            char t = chars[i];
            chars[i] = chars[size - 1 - i];
            chars[size - 1 - i] = t;
        }
        return new String(chars);
    }
}
